package cn.wolfcode.qo;

import cn.hutool.core.date.DateUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//封装结算报表查询的参数 封装高级查询
//拼接 where子句 #  group by $ select $
@Getter
@Setter
public class ConsumptionReportQueryObject extends QueryObject {
    private String groupType = "门店";//根据门店查询
    private Long businessId;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginCreateTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endCreateTime;
    private Boolean appointmentType;

    private static Map<String,String> groupTypeMap=new HashMap<>();

    static {
        groupTypeMap.put("门店","b.name");
        groupTypeMap.put("年","DATE_FORMAT(c.create_time,'%Y')");
        groupTypeMap.put("月","DATE_FORMAT(c.create_time,'%Y-%m')");
        groupTypeMap.put("日","DATE_FORMAT(c.create_time,'%Y-%m-%d')");
    }

    public String getGroupTypeName(){
        return groupTypeMap.get(this.groupType);
    }

    //把时间转成 这天的最后一刻
    public Date getEndCreateTime(){
        /*if (this.endCreateTime != null) {
            return DateUtil.endOfDay(this.endCreateTime);
        }*/
        return this.endCreateTime != null ? DateUtil.endOfDay(this.endCreateTime):null;
    }

}
